package com.dkd.sbtz.mapper;

import java.util.List;

import com.dkd.sbtz.domain.AssetAssessment;
import com.dkd.sbtz.domain.AssetMtplan;
import com.dkd.sbtz.domain.AssetMtplanSpare;
import com.dkd.sbtz.domain.mtplan.MtplanSpareHistoryVO;
import com.dkd.sbtz.domain.plando.*;
import com.dkd.sbtz.domain.vo.PlanQuery;
import org.apache.ibatis.annotations.Param;

/**
 * 设备计划维护Mapper接口
 * 
 * @author xzj
 * @date 2025-09-19
 */
public interface AssetMtplanMapper 
{

    /** 列表（按 assetId / keyword / 日期 / status / needSpare）- 若依分页用 startPage() */
    List<AssetMtplan> selectAssetMtplanList(AssetMtplan query);

    /** 详情（按 planId 主键） */
    AssetMtplan selectAssetMtplanById(@Param("id") Long id);

    int insertAssetMtplan(AssetMtplan po);

    int insertAssetMtplanTmp(AssetMtplan po);

    int updateAssetMtplan(AssetMtplan po);

    int deleteAssetMtplanByIds(@Param("ids") Long[] ids);

    int deleteByPlanId(@Param("planId") Long planId);

    int batchInsert(@Param("list") List<AssetMtplanSpare> list);

    /** 明细展示：带 spareName / spareCode */
    List<AssetMtplanSpare> selectByPlanId(@Param("planId") Long planId);

    int updatePlanFields(AssetMtplan po);

    List<AssetMtplanSpare> selectSpareInfoByPlanIds(@Param("planIds") List<Long> planIds);


    /*从asset_mtplan_spare 里面 根据asset_id 查询设备的历史备件更换 */
    List<MtplanSpareHistoryVO> selectHistoryByAssetId(
            @Param("assetId") Long assetId,
            @Param("planId") Long planId,
            @Param("keyword") String keyword,
            @Param("beginTime") String beginTime,
            @Param("endTime") String endTime
    );

    int insertOrUpdate(AssetMtplanSpare r);




    /** 取计划涉及到的备件ID（去重） */
    List<Long> selectSpareIdsByPlanIds(@Param("planIds") List<Long> planIds);

    /** 删除关系表中这些计划的记录 */
    int deleteByPlanIds(@Param("planIds") List<Long> planIds);

    /** 这些备件中，仍被其它计划引用的（删除关系后即可直接查） */
    List<Long> selectInUseSpareIds(@Param("spareIds") List<Long> spareIds);

    List<AssetMtplan> selectAllTmp();

    int deleteAllTmp();
}
